/**
 * Copyright &copy; com.smooth.common
 */
package com.smooth.sys.pc.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smooth.common.site.common.rsp.ReturnResult;
import com.smooth.common.site.common.web.BaseController;
import com.smooth.sys.pc.vo.SmsCodeReq;
import com.smooth.sys.site.biz.member.gen.service.BizMemberService;
import com.smooth.sys.site.biz.sms.bx.service.SmsCodeService;
import com.taobao.api.ApiException;

/**
 * 订单Controller
 * @author 北冥
 * @version 2018-02-10
 */
@Controller
@RequestMapping(value = "/pc")
public class PcSmsnController extends BaseController {
	@Autowired
	BizMemberService bizMemberService;
	@Autowired
	SmsCodeService smsCodeService;
	protected Logger logger = LoggerFactory.getLogger(getClass());
	
	@RequestMapping(value = {"p/sms/sendMobileCode"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult sendMobileCode(@Valid SmsCodeReq smsCodeReq, BindingResult result,HttpServletRequest request, HttpServletResponse response) throws ApiException {
		ReturnResult returnResult = new ReturnResult();
		String code = smsCodeService.sendMobileCode(smsCodeReq);
		logger.info("code is "+code);
//		returnResult.setData("code",code);
		return returnResult;
	}
	
	@RequestMapping(value = {"p/sms/veryMobileCode"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult getMobileCode(@RequestParam(required=true) String telNo,@RequestParam(required=true) String veryCode, HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		if(!smsCodeService.verfyCode(telNo, veryCode)) {
			returnResult.setStatus(520);
		}
		return returnResult;
	}
}